package tool

/**
 * @className function
 * @author liyang<654516092@qq.com>
 * @date 2021/4/14 15:22
 */

//格式化证书
func FormatCertKey(key string) string {
	var publicHeader = "-----BEGIN CERTIFICATE-----\n"
	var publicTail = "-----END CERTIFICATE-----\n"
	var temp string
	split(key,&temp)
	return publicHeader+temp+publicTail
}

//格式化获取公钥
func FormatPublicKey(key string) string {
	var publicHeader = "-----BEGIN PUBLIC KEY-----\n"
	var publicTail = "-----END PUBLIC KEY-----\n"
	var temp string
	split(key,&temp)
	return publicHeader+temp+publicTail
}

//获取格式化私钥
func FormatPrivateKey(key string ) string {
	var publicHeader = "-----BEGIN RSA PRIVATE KEY-----\n"
	var publicTail = "-----END RSA PRIVATE KEY-----\n"
	var temp string
	split(key,&temp)
	return publicHeader+temp+publicTail
}
//64个字符换行
func split(key string,temp *string){
	if len(key)<=64 {
		*temp = *temp+key+"\n"
	}
	for i:=0;i<len(key);i++{
		if (i+1)%64==0{
			*temp = *temp+key[:i+1]+"\n"
			key = key[i+1:]
			split(key,temp)
			break
		}
	}
}